package com.imay.live.activity.authentication;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.text.InputFilter;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.imay.base.util.StringUtil;
import com.imay.live.activity.BaseRequestActivity;
import com.imay.live.cache.UserInfoCache;
import com.imay.live.helper.DialogFragmentHelper;
import com.imay.live.helper.EventHelper;
import com.imay.live.model.IdentStatusModel;
import com.imay.live.model.UserInfoModel;
import com.imay.live.pay.AuthResult;
import com.imay.live.pay.PayUtils;
import com.imay.live.proto.ErrorResult;
import com.imay.live.proto.Result;
import com.imay.live.proto.helper.ProtoCallBack;
import com.imay.live.proto.helper.ProtoHttpFactory;
import com.imay.live.proto.helper.ProtoRequestHelper;
import com.imay.live.utils.ToastUtil;
import com.imay.live.R;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.imay.live.proto.ResultCode.CodeSuccess;

/**
 * Created by lzx on 2017/04/20 0020.
 * 用户认证
 */

public class AuthenticationActivity extends BaseRequestActivity {
    LinearLayout linearLayout;
    EditTextView editTextView, editNo;
    PayUtils payUtils;
    PassButton passButton;
    IdentStatusModel identStatusModel;

    public static void startActivity(Context context) {
        Intent starter = new Intent(context, AuthenticationActivity.class);
        context.startActivity(starter);
    }

    public static void startForResult(Activity activity, int requestCode) {
        Intent starter = new Intent(activity, AuthenticationActivity.class);
        activity.startActivityForResult(starter, requestCode);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.authent_layout;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setTitle(getString(R.string.auto_title));
        linearLayout = $(R.id.src_linear);
        linearLayout.setBackgroundColor(getResources().getColor(R.color.bg_f3));
        getinfo();

    }

    @Override
    public void comeBack() {
        if (identStatusModel != null && identStatusModel.getRealNameStatus() == 3) {
            setResult(RESULT_OK);
        }
        finish();
    }

    private void init(IdentStatusModel identStatusModel) {
        this.identStatusModel = identStatusModel;
        UserInfoModel userInfoModel = UserInfoCache.getUserInfo();
        if (userInfoModel != null) {
            userInfoModel.setRealNameStatus(identStatusModel.getRealNameStatus());
            UserInfoCache.saveUserInfo(userInfoModel);
        }
        linearLayout.removeAllViews();
        //	实名审核状态 0:未激活,1:激活认证审核,2审核失败,3审核成功
        EventHelper.postAuthChange(identStatusModel.getRealNameStatus());
        if (identStatusModel.getRealNameStatus() == 3) {
            View view = getShowstatus(linearLayout);
            id_show_status.setText(getResources().getString(R.string.auth_pass));
            show_image.setImageResource(R.mipmap.bg_05_shimrz_pass_iconograph);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.gravity = Gravity.CENTER;
            linearLayout.addView(view, params);
        } else if (identStatusModel.getRealNameStatus() == 1) {

            View view = getShowstatus(linearLayout);
            id_show_status.setText(getResources().getString(R.string.auth_waiting));
            show_image.setImageResource(R.mipmap.bg_05_shimrz_waiting_iconograph);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.gravity = Gravity.CENTER;
            linearLayout.addView(view, params);
        } else {

            editTextView = new EditTextView(this, 0);
            editNo = new EditTextView(this, 1);
            editTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_NEXT) {
                        editNo.setFocusable();
                        return true;
                    }
                    return false;
                }
            });

            passButton = new PassButton(this);
            LinearLayout.LayoutParams topparams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            topparams.topMargin = (int) getResources().getDimension(R.dimen.auto_top);
            linearLayout.addView(editTextView, topparams);
            linearLayout.addView(editNo);
            editNo.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        if (v.getWindowToken() != null) {
                            v.setFocusable(false);
                            InputMethodManager inputManager =
                                    (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                            inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
                        }

                    }
                    return false;
                }
            });
//            editNo.addTextChangedListener(new TextWatcher() {
//                @Override
//                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//                }
//
//                @Override
//                public void onTextChanged(CharSequence s, int start, int before, int count) {
////                    if (s.length() >= 18 && editTextView.getText().length() > 0) {
////                        passButton.setStatus(true);
////                    } else {
////                        passButton.setStatus(false);
////                    }
//                }
//
//                @Override
//                public void afterTextChanged(Editable s) {
//                }
//            });
            TextView statusTips = new TextView(this);
            TextView bottomTips = null;
            if (identStatusModel.getRealNameStatus() == 2) {
                View statusView = getShowstatus(linearLayout);
                id_show_status.setText(getResources().getString(R.string.auth_cardfail));
                show_image.setImageResource(R.mipmap.bg_05_shimrz_notpass_iconograph);
                LinearLayout.LayoutParams statusparams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//                params.gravity = Gravity.CENTER;
                statusparams.weight = 1;
                linearLayout.addView(statusView, statusparams);


                editTextView.setText(identStatusModel.getRealName());
                editNo.setText(identStatusModel.getIdentificationNum());
                statusTips.setTextColor(getResources().getColor(R.color.color_ff));
//                审核失败时有效，0:人工审核, 11:支付宝未实名,12:支付宝帐号已经被认证过了,13:其他原因(例如去支付宝获取用户信息过程中出现的错误)
                if (identStatusModel.getRealNameFailedReason() == 0) {
                    statusTips.setTextColor(getResources().getColor(R.color.text_b2));
                    statusTips.setText(getResources().getString(R.string.auto_statustips));
//                    statusTips.setText(getResources().getString(R.string.auth_cardfail0));
                } else if (identStatusModel.getRealNameFailedReason() == 11) {
                    statusTips.setText(getResources().getString(R.string.auth_cardfail1));
                } else if (identStatusModel.getRealNameFailedReason() == 12) {
                    statusTips.setText(getResources().getString(R.string.error_114));
                } else if (identStatusModel.getRealNameFailedReason() == 14) {
                    statusTips.setText(identStatusModel.getFaildes());
                } else {
                    statusTips.setText(getResources().getString(R.string.auth_cardfail13));
                }

            } else {
                bottomTips = new TextView(this);
                statusTips.setTextColor(getResources().getColor(R.color.text_b2));
                statusTips.setText(getResources().getString(R.string.auto_statustips));
            }
            int left = (int) getResources().getDimension(R.dimen.pro_tips_left);
            int top = (int) getResources().getDimension(R.dimen.auth_tips_top);
            statusTips.setPadding(left, top, left, 0);


            statusTips.setGravity(Gravity.CENTER_HORIZONTAL);
            statusTips.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.tips_size));
            linearLayout.addView(statusTips);

            linearLayout.addView(passButton);


            TextView other = otherTips();
            LinearLayout.LayoutParams otherparams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            otherparams.topMargin = (int) getResources().getDimension(R.dimen.auth_other_top);
            otherparams.bottomMargin = (int) getResources().getDimension(R.dimen.auth_other_bottom);
            linearLayout.addView(other, otherparams);

            if (bottomTips != null) {
                bottomTips.setPadding(left, top, left, top);
                bottomTips.setText(getResources().getString(R.string.auto_bottomtips));
                bottomTips.setTextColor(getResources().getColor(R.color.text_b2));
                bottomTips.setGravity(Gravity.CENTER_HORIZONTAL);
                bottomTips.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.auth_bottom_size));
                LinearLayout.LayoutParams bottomTipsparams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                bottomTipsparams.topMargin = (int) getResources().getDimension(R.dimen.auto_bottom_top);
                linearLayout.addView(bottomTips, bottomTipsparams);
            }

        }
    }

    private void getinfo() {
        ProtoRequestHelper.task(ProtoHttpFactory.getrealNameStatus()).setTag(this.hashCode()).request(new ProtoCallBack() {
            @Override
            public void onRequestSuccess(String command, String data) {
                Result<IdentStatusModel> result = JSON.parseObject(data, new TypeReference<Result<IdentStatusModel>>() {
                }.getType());
                if (result.result == CodeSuccess && result.data != null) {
                    init(result.data);
                }
            }

            @Override
            public void onRequestError(String command, int code, String message) {
                ToastUtil.show(AuthenticationActivity.this, ErrorResult.getString(AuthenticationActivity.this, code));
            }
        });
    }

    /**
     * 其他认证
     *
     * @return
     */
    private TextView otherTips() {
        TextView other = new TextView(this);
        other.setGravity(Gravity.CENTER_HORIZONTAL);
        String othertips = getResources().getString(R.string.auto_other);
        other.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.auth_other_size));
        SpannableString spanstring = new SpannableString(othertips);
        int start = othertips.indexOf(",") + 1;
        spanstring.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
//                if (passButton.getStatus()) {
                if (checkchinese()) {
                    nameCheck(0, editTextView.getText().toString(), editNo.getText().toString().trim());
//                        AuthentCardActivity.startActivityForResult(AuthenticationActivity.this, editTextView.getText().toString(), editNo.getText().toString(), AuthentCardActivity.RECODE);
                }
//                } else {
//                    ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.auth_edittips));
//                }
            }

            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor(Color.parseColor("#507daf"));
                ds.setUnderlineText(false);
//                ds.clearShadowLayer();
            }
        }, start, othertips.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        other.setText(spanstring);
        other.setMovementMethod(LinkMovementMethod.getInstance());
        return other;
    }

    class EditTextView extends EditText {
        private Paint paint;
        private Path path;
        private int tag = 0;

        public EditTextView(Context context, int tag) {
            super(context);
            this.tag = tag;
            init(context);
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            if (path == null) {
                path = new Path();
                paint = new Paint();
                paint.setStyle(Paint.Style.STROKE);
                paint.setAntiAlias(true);
                paint.setStrokeWidth(4);
                paint.setColor(getResources().getColor(R.color.divider_f0));
            }
            path.reset();
            path.moveTo(0, canvas.getHeight());
            path.lineTo(canvas.getWidth(), canvas.getHeight());
            canvas.drawPath(path, paint);
        }

        private void init(Context context) {
            setBackgroundColor(context.getResources().getColor(R.color.bg_window));
            setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFocusable(true);
                    setFocusableInTouchMode(true);
                    requestFocus();
                    InputMethodManager inputManager =
                            (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputManager.showSoftInput(EditTextView.this, 0);
                }
            });
            setFocusable(false);
            setHintTextColor(getResources().getColor(R.color.text_b2));
            setTextColor(getResources().getColor(R.color.text_4a));
            setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.auth_name_size));
            setSingleLine();
            int left = (int) getResources().getDimension(R.dimen.auto_paddingleft);
            setPadding(left, 0, left, 0);

            if (tag == 0) {
                setInputType(InputType.TYPE_CLASS_TEXT);
                setHint(getResources().getString(R.string.profit_reallyname));
                setImeOptions(EditorInfo.IME_ACTION_NEXT);

            } else {
                setHint(getResources().getString(R.string.auto_id));
                setFilters(new InputFilter[]{new InputFilter.LengthFilter(18), new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                        for (int i = start; i < end; i++) {
                            String regex = "^[\u4E00-\u9FA5]+$";
                            boolean isChinese = Pattern.matches(regex, source.toString());
                            if (!Character.isLetterOrDigit(source.charAt(start)) || isChinese) {
                                return "";
                            }
                            return null;
                        }
                        return null;
                    }
                }});
                setImeOptions(EditorInfo.IME_ACTION_DONE);
                setInputType(InputType.TYPE_CLASS_TEXT);
            }
        }

        public void setFocusable() {
            setFocusable(true);
            setFocusableInTouchMode(true);
            requestFocus();
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((int) getResources().getDimension(R.dimen.profitreally_height), MeasureSpec.EXACTLY));
        }
    }

    private boolean checkchinese() {
        String name = editTextView.getText().toString().trim();
        if (StringUtil.isEmpty(name)) {
            ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.auth_namenull));
            return false;
        }
        boolean chines = false;
        for (int i = 0; i < name.length(); i++) {
            chines = isChineseChar(String.valueOf(name.charAt(i)));
            if (!chines) {
                break;
            }
        }
        if (!chines) {
            ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.error_232));
            return false;
        } else {
            if (editNo.getText().toString().length() == 18) {
                return true;
            }
            if (editNo.getText().toString().length() == 0) {
                ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.auth_nonull));
                return false;
            }
            ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.auth_edittips));
        }
        return false;
    }

    public static boolean isChineseChar(CharSequence charSequence) {
        boolean temp = false;
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher m = p.matcher(charSequence);
        if (m.find()) {
            temp = true;
        }
        return temp;
    }

    /**
     * 认证按钮
     */
    class PassButton extends LinearLayout {
        TextView textView;
//        boolean click;

        public PassButton(Context context) {
            super(context);
            inint(context);
        }

        void inint(Context context) {
            setOrientation(VERTICAL);
            textView = new TextView(context);
            textView.setGravity(Gravity.CENTER);
            textView.setPadding(0, (int) getResources().getDimension(R.dimen.re_button_padding), 0, (int) getResources().getDimension(R.dimen.re_button_padding));

            LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_HORIZONTAL;
            params.topMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            params.bottomMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            params.leftMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            params.rightMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (checkchinese()) {
                        DialogFragmentHelper.showLoadingDialog(getSupportFragmentManager(), getString(R.string.str_loading));
//                        getzhifubaoCode();
                        nameCheck(1, editTextView.getText().toString().trim(), editNo.getText().toString().trim());

                    }
                }
            });
            textView.setText(getResources().getString(R.string.auto_zhifubao));
            textView.setTextColor(getResources().getColor(R.color.text_ff));
            textView.setBackground(getResources().getDrawable(R.drawable.shape_corner100_9e));
            addView(textView, params);
        }

//        public void setStatus(boolean click) {
//            if (click) {
//                textView.setBackground_fillcolor(getResources().getColor(R.color.color_020202));
//            } else {
//                textView.setBackground_fillcolor(getResources().getColor(R.color.color_b2b2b2));
//            }
//            if (this.click != click) {
//                textView.invalidate();
//            }
//            this.click = click;
//        }
//
//        public boolean getStatus() {
//            return click;
//        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            comeBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 对输入的信息进行身份验证
     *
     * @param realName
     * @param idNum
     */
    private void nameCheck(final int type, final String realName, final String idNum) {
        ProtoRequestHelper.task(ProtoHttpFactory.getrealNameCheckID(realName, idNum)).setTag(this.hashCode()).request(new ProtoCallBack() {
            @Override
            public void onRequestSuccess(String command, String data) {
                DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
                try {
                    Result<String> result = JSON.parseObject(data, new TypeReference<Result<String>>() {
                    }.getType());
                    if (result.result == CodeSuccess) {
                        if ("T".equals(result.data)) {
                            if (type == 0) {
                                AuthentCardActivity.startActivityForResult(AuthenticationActivity.this, realName, idNum, AuthentCardActivity.RECODE);
                            } else {
                                getzhifubaoCode();
                            }
                        } else {
                            ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.auth_zhifubaoback));
//                            DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(),getResources().getString(R.string.auth_zhifubaoback), new View.OnClickListener() {
//                                @Override
//                                public void onClick(View v) {
//
//                                }
//                            });
                        }

                    } else {
                        ToastUtil.show(AuthenticationActivity.this, ErrorResult.getString(AuthenticationActivity.this, result.result));
//                        DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), ErrorResult.getString(AuthenticationActivity.this, result.result), new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//
//                            }
//                        });
                    }
                } catch (Exception e) {

                }
            }

            @Override
            public void onRequestError(String command, int code, String message) {
                ToastUtil.show(AuthenticationActivity.this, ErrorResult.getString(AuthenticationActivity.this, code));
                DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
            }
        });
    }

    /**
     * 支付宝验证结果
     *
     * @param authCode
     */
    private void verifyAuthCode(String authCode) {
        ProtoRequestHelper.task(ProtoHttpFactory.getrealNameGetVerify(editTextView.getText().toString().trim(), editNo.getText().toString().trim(), authCode)).setTag(this.hashCode()).request(new ProtoCallBack() {
            @Override
            public void onRequestSuccess(String command, String data) {
                DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
                try {
                    Result<String> result = JSON.parseObject(data, new TypeReference<Result<String>>() {
                    }.getType());
                    IdentStatusModel identStatusModel = new IdentStatusModel();
                    if (result.result == CodeSuccess) {
                        if ("T".equals(result.data)) {
                            identStatusModel.setRealNameStatus(3);
                        } else {
                            identStatusModel.setRealNameStatus(2);
                            // 认证未通过,请确保支付宝完成实名认证
                            identStatusModel.setRealNameFailedReason(11);// A 原因  文本保存
                        }
                    } else {// 需要展示在错误界面，非弹窗 同上
                        identStatusModel.setRealNameStatus(2);
                        // 认证未通过,请确保支付宝完成实名认证
                        identStatusModel.setRealNameFailedReason(14);// A 原因  文本保存
                        identStatusModel.setFaildes(ErrorResult.getString(AuthenticationActivity.this, result.result));
                    }
                    identStatusModel.setRealName(editTextView.getText().toString());
                    identStatusModel.setIdentificationNum(editNo.getText().toString());
                    UserInfoModel model = UserInfoCache.getUserInfo();
                    if (model != null) {
                        model.setRealNameStatus(identStatusModel.getRealNameStatus());
                    }
                    init(identStatusModel);
                } catch (Exception e) {

                }
            }

            @Override
            public void onRequestError(String command, int code, String message) {
                DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
                if (code == -1) {
                    code = 1;
                }
                IdentStatusModel identStatusModel = new IdentStatusModel();
                identStatusModel.setRealNameStatus(2);
                // 认证未通过,请确保支付宝完成实名认证
                identStatusModel.setRealNameFailedReason(14);// A 原因  文本保存
                identStatusModel.setFaildes(ErrorResult.getString(AuthenticationActivity.this, code));
                identStatusModel.setRealName(editTextView.getText().toString());
                identStatusModel.setIdentificationNum(editNo.getText().toString());
                UserInfoModel model = UserInfoCache.getUserInfo();
                if (model != null) {
                    model.setRealNameStatus(identStatusModel.getRealNameStatus());
                }
                init(identStatusModel);
            }
        });
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == PayUtils.SDK_AUTH_FLAG) {
                @SuppressWarnings("unchecked")
                AuthResult authResult = new AuthResult((Map<String, String>) msg.obj, true);
                String resultStatus = authResult.getResultStatus();
                // 判断resultStatus 为“9000”且result_code
                // 为“200”则代表授权成功，具体状态码代表含义可参考授权接口文档
                if (TextUtils.equals(resultStatus, "9000") && TextUtils.equals(authResult.getResultCode(), "200")) {
                    // 获取alipay_open_id，调支付时作为参数extern_token 的value
                    // 传入，则支付账户为该授权账户
                    verifyAuthCode(authResult.getAuthCode());
                } else {
                    // 其他状态值则为授权失败
                    DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
                    ToastUtil.show(AuthenticationActivity.this, getResources().getString(R.string.auth_fail));

                }
            }
        }
    };
    ImageView show_image;
    TextView id_show_status;

    private View getShowstatus(ViewGroup viewGroup) {
        View view = LayoutInflater.from(AuthenticationActivity.this).inflate(R.layout.id_showstatus_item, viewGroup, false);
        show_image = (ImageView) view.findViewById(R.id.show_image);
        id_show_status = (TextView) view.findViewById(R.id.id_show_status);
        return view;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == AuthentCardActivity.RECODE) {
            if (resultCode == Activity.RESULT_OK) {
                IdentStatusModel identStatusModel = new IdentStatusModel();
                identStatusModel.setRealNameStatus(1);
                identStatusModel.setRealNameFailedReason(11);
                init(identStatusModel);
            }
        }

    }

    private void getzhifubaoCode() {
        if (payUtils == null) {
            payUtils = new PayUtils(AuthenticationActivity.this);
        }
        ProtoRequestHelper.task(ProtoHttpFactory.getrealNameGetVerifyPara()).setTag(this.hashCode()).request(new ProtoCallBack() {
            @Override
            public void onRequestSuccess(String command, String data) {
                try {
                    Result<String> result = JSON.parseObject(data, new TypeReference<Result<String>>() {
                    }.getType());
                    if (result.result == CodeSuccess) {
                        payUtils.authV2(result.data, handler);
                        return;
                    } else {
                        ToastUtil.show(AuthenticationActivity.this, ErrorResult.getString(AuthenticationActivity.this, result.result));
//                        DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), ErrorResult.getString(AuthenticationActivity.this, result.result), new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//
//                            }
//                        });
                    }
                } catch (Exception e) {

                }
                DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
            }

            @Override
            public void onRequestError(String command, int code, String message) {
                ToastUtil.show(AuthenticationActivity.this, ErrorResult.getString(AuthenticationActivity.this, code));
                DialogFragmentHelper.closeLoadingDialog(getSupportFragmentManager());
            }
        });
    }
}
